//
//  HBBaseController.m
//  HeartBeat
//
//  Created by karong on 2023/8/23.
//

#import "HBBaseController.h"

@interface HBBaseController ()
@property(nonatomic, strong) UIButton * leftBtn;
@property (weak, nonatomic) UIView *baseNavBarView;

@end

@implementation HBBaseController

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

//- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
//    [super traitCollectionDidChange:previousTraitCollection];
//    self.view.backgroundColor = UIColor.bg_gray_f2f2f2;
//    [self initNavBarView];
//    [self styleDidChange];
//}
//
///// 暗黑模式发生变化時，在这里重新设置UI樣式
//- (void)styleDidChange {
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.font_white_ffffff;
    [self initNavBarView];
    UIButton *btn = [self.view viewWithTag:1002];
    if(btn) {
        [btn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    }
}

// 初始化导航栏
- (void)initNavBarView {
    if(self.baseNavBarView) {
        if (![self.baseNavBarView isKindOfClass:NSClassFromString(@"UIView")]) {
            UILabel *label = [self.view viewWithTag:1003];
            label.textColor = UIColor.font_white_ffffff;
            label.font = [UIFont systemFontOfSize:18 weight:(UIFontWeightMedium)];
        }
    }
}

// 设置标題
- (void)setTitle:(NSString *)title {
    [super setTitle:title];
    UILabel *label = [self.view viewWithTag:1003];
    label.text = title;
}

- (void)backAction:(id)sender {
    if(self.navigationController) {
        if (self.navigationController.viewControllers.firstObject == self) {
            [self dismissViewControllerAnimated:YES completion:nil];
        }
        else {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)popVC {
    [self.navigationController popViewControllerAnimated:YES];
}

- (UIView *)baseNavBarView {
    if (!_baseNavBarView) {
        _baseNavBarView = [self.view viewWithTag:1001];
    }
    return _baseNavBarView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
